#include <Wire.h>

uint8_t outbuf[] = { 0xf2, 0x79, 0x2e, 0x7d,
  0x4d, 0x43, 0x01, 0xfd
};				// sample data set


int ledPin = 13;

void
receiveEvent (int howMany)
{
  digitalWrite (ledPin, HIGH);	// sets the LED on

  while (Wire.available ())
    {
      char c = Wire.receive ();	// receive byte as a character

    }
}
void
requestEvent ()
{
  digitalWrite (ledPin, HIGH);	// sets the LED on

  uint8_t output[6];
  output[0] = nunchuk_encode_byte (0xf2);
  Wire.send (outbuf, 8);	// send data packet
}

void
setup ()
{
  pinMode (ledPin, OUTPUT);	// sets the digital pin as output

  Wire.begin (0x52);		// join i2c bus with address 0x52
  Wire.onReceive (receiveEvent);	// register event
  Wire.onRequest (requestEvent);	// register event
}

void
loop ()
{
  delay (100);
}


char
nunchuk_encode_byte (char x)
{
  x = x - 0x17;
  x = (x ^ 0x17);
  return x;
}
